package com.demo.util;

import java.util.concurrent.ThreadPoolExecutor;

/**
 * 使用了 synchronized 加锁
 * @author liangalong[liangalong2022@aliyun.com]
 * @date 2023-04-13 12:07
 * */
public class SynchronizedDemo {

    public static int ticktNum = 100;

    public static void main(String[] args) {
        ThreadPoolExecutor executor = new ThreadPoolConfig2().ThreadPoolExecutor();
        executor.execute(new Runnable() {
            public void run() {
                method();
            }
        });
        executor.shutdown();
    }

    public static synchronized void method() {
        while (true){
            if (ticktNum > 0) {
                String name = Thread.currentThread().getName();
                ticktNum--;
                System.out.println("当前线程名称："+name+"---当前余票："+ticktNum);
            }else {
                break;
            }
        }
    }

}
